home *** CD-ROM | disk | FTP | other *** search
- {+--------------------------------------------------------------------------+
- | Unit: DemoUnit
- | Created: 8.97
- | Author: Martin Waldenburg
- | Copyright 1997, all rights reserved.
- | Description: Demo for the FixRecSort engine.
- | Version: 1.0
- | Status FreeWare
- | It's provided as is, without a warranty of any kind.
- | You use it at your own risc.
- | E-Mail me at Martin.Waldenburg@t-online.de
- +--------------------------------------------------------------------------+}
- unit DemoUn;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, mwFixedRecSort, mwFastTime;
-
- type
- PDemoData = ^TDemoData;
- TDemoData = record
- Number: Integer;
- Data1: String[10];
- Data2: String[30];
- end;
- TForm1 = class(TForm)
- Button1: TButton;
- OpenDialog1: TOpenDialog;
- Label1: TLabel;
- Button2: TButton;
- Time1: TmwFastTime;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- FixRecSort: TFixRecSort;
- public
- { Public-Deklarationen }
- end;
-
- var
- Form1: TForm1;
- DemoData: PDemoData;
- DData: TDemoData;
-
- implementation
-
- {$R *.DFM}
-
- function Compare(Item1, Item2: Pointer): Integer;
- begin
- Result:= CompareText(PDemoData(Item1)^.Data1, PDemoData(Item2)^.Data1);
- { The comparision with the typecast is very comfortable but cost lots of time.
- However, you will find this only noticeable when sorting Files that fit in
- Memory, for large amounts of Records (Millions) windows file buffering system
- will equalize this.
- The faster way is do do a comparision from position one to position two.}
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- FixRecSort:= TFixRecSort.Create(48);
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- FixRecSort.Free;
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- if OpenDialog1.Execute then
- begin
- FixRecSort.Init(OpenDialog1.FileName);
- FixRecSort.MaxLines:= 200000;
- FixRecSort.MaxMem:= 4000000;
- Time1.Start;
- FixRecSort.Start(Compare);
- Time1.Stop;
- Label1.Caption:= Time1.ElapsedTime;
- end;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- Close;
- end;
-
- end.
-